"""
FileName：home_page.py
Description：
Author：gaojiahui
Time：2025/8/29 18:37
Website：https://gitee.com/gao-jiahui
"""
from selenium.webdriver.common.by import By

from config.config import Config
from pages.base_page import BasePage


class HomePage(BasePage):
    # 定位器
    CLOSE_COUPON_ICON = (By.CSS_SELECTOR, "i[class*='close-icon']")
    LOGIN_LINK = (By.CSS_SELECTOR, "a[href*='login']")
    SEARCH_BAR = (By.CLASS_NAME, "search-input")
    SEARCH_BUTTON = (By.CSS_SELECTOR, "button[class*='search-btn']")
    Cart_ICON = (By.CSS_SELECTOR, "a[href*='cart']")
    USER_ICON = (By.LINK_TEXT, "我的账户")

    def __init__(self, driver):
        super().__init__(driver)
        self.driver.get(Config.BASE_URL)
        self.click(self.CLOSE_COUPON_ICON)

    def navigate_to_login(self):
        self.click(self.LOGIN_LINK)
        from pages.login_page import LoginPage
        return LoginPage(self.driver)

    def search_for_product(self, product_name):
        self.send_keys(self.SEARCH_BAR, product_name)
        self.click(self.SEARCH_BUTTON)
        from pages.search_page import SearchPage
        return SearchPage(self.driver)

    def navigate_to_cart(self):
        self.click(self.Cart_ICON)
        from pages.cart_page import CartPage
        return CartPage(self.driver)

    def navigate_to_user_center(self):
        self.click(self.USER_ICON)
        from pages.member_page import MemberPage
        return MemberPage(self.driver)
